package br.usp.ime.dojo.core.repositories.impl.db;

import java.util.ArrayList;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;

import br.usp.ime.dojo.core.entities.DojoRoom;
import br.usp.ime.dojo.core.exceptions.DuplicatedRoomException;
import br.usp.ime.dojo.core.repositories.DojoRoomRepository;

public class DojoRoomRepositoryInDB implements DojoRoomRepository {
	
	private static DojoRoomRepositoryInDB instance = null;
	
	public static DojoRoomRepositoryInDB getInstance() {
		if (instance == null) {
			instance = new DojoRoomRepositoryInDB();
		}
		return instance;
	}
	
	private DojoRoomRepositoryInDB() {}

	public void addRoom(DojoRoom dojoRoom) throws DuplicatedRoomException {
		PersistenceManager persistenceManager = DojoPersistenceManagerFactory.get();
		persistenceManager.makePersistent(dojoRoom);
		persistenceManager.close();
	}

	public void clearAll() {
		PersistenceManager persistenceManager = DojoPersistenceManagerFactory.get();
		Query query = persistenceManager.newQuery("delete * from DojoRoom");
		query.execute();
	}

	public int count() {
		PersistenceManager persistenceManager = DojoPersistenceManagerFactory.get();
		Query query = persistenceManager.newQuery("select count(*) from DojoRoom");
		//return query.execute();
		return 0;
	}

	public DojoRoom get(String roomName) {
		// TODO Auto-generated method stub
		return null;
	}

	public ArrayList<DojoRoom> getDojoRoomList() {
		// TODO Auto-generated method stub
		return null;
	}

}
